package com.laoyao.controller;

import java.sql.SQLException;

import com.jfinal.core.Controller;
import com.laoyao.beans.PageBean;
import com.laoyao.comm.config.CrossOrigin;
import com.laoyao.comm.model.Collect;
import com.laoyao.service.CollectService;
import com.laoyao.util.DateUtil;

@CrossOrigin
public class CollectController extends Controller {
	//添加收藏
	public void index(){
		Collect c = getBean(Collect.class,"");
		Integer flag = getParaToInt("flag");
		
		if(flag==0){
			renderJson("success",c.delete());
		}
		if(flag==1){
			try{
				c.setTime(DateUtil.getTime());
				renderJson("success",c.save());
			}catch(Exception e){
				e.printStackTrace();
			}
			
		}
	}
	
	public void list(){
		PageBean p = getBean(PageBean.class,"");
		String id = getPara("id");
		renderJson("page",CollectService.me.list(p.getPageNumber(), p.getPageSize(), id));
	}
	
	public void del(){
		Collect c = getBean(Collect.class,"");
		renderJson("success",c.delete());		
	}
	
}
